#pragma once

#include "Reactor.hpp"
#include "Sock.hpp"
#include "Service.hpp"

int Accepter(Event *evp)
{
    std::cout << "有新的链接到来,就绪sock:" << evp->sock << std::endl;
    while (true)
    {
        int sock = Sock::Accept(evp->sock);
        if (sock < 0)
        {
            std::cout << " Accept Done" << std::endl;
            break;
        }
        SetNonBlock(sock); //设置非阻塞
        //获取链接成功，构建Event结构
        Event *other_ev = new Event();
        other_ev->sock = sock;
        other_ev->R = evp->R;
        // recver,sender,errorer,就是代码中的较顶层，只负责真正的读取
        other_ev->RegisterCallback(Recver, Sender, Errorer);

        evp->R->InsertEvent(other_ev, EPOLLIN | EPOLLET);
    }
}